#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
	int a[10000] = {0};
    int group ,amout = 0;
    cin >> group ;
    for (int i=0;i<group ; i++)
    {
        cin >> a[i] ;
    }
    sort(a,a+group);
    int t = 0;
    while (true)
    {
        a[1] = a[0]+a[1];
        if (t!=0)
            amout +=a[0];
        t++;
        a[0] = 30000;
        sort(a,a+group);
        if (a[0]>=30000)
            break;
    }  

/*
    for (int j = 0;j < group; j++)
        cout << a[j] << " ";
    cout << endl;

*/
    printf("%d\n",amout);

	return 0;
}